package com.flnet.web.controller.foxwash;

import com.flnet.common.annotation.Log;
import com.flnet.common.base.AjaxResult;
import com.flnet.common.enums.BusinessType;
import com.flnet.common.page.TableDataInfo;
import com.flnet.common.utils.UUIDUtils;
import com.flnet.common.utils.poi.ExcelUtil;
import com.flnet.foxwash.domain.WShopPrice;
import com.flnet.foxwash.domain.WVendor;
import com.flnet.foxwash.service.IWVendorService;
import com.flnet.framework.util.ShiroUtils;
import com.flnet.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 供应商 信息操作处理
 * 
 * @author flnet
 * @date 2019-03-20
 */
@Controller
@RequestMapping("/foxwash/wVendor")
public class WVendorController extends BaseController
{
    private String prefix = "foxwash/wVendor";
	
	@Autowired
	private IWVendorService wVendorService;
	
	@RequiresPermissions("foxwash:wVendor:view")
	@GetMapping()
	public String wVendor()
	{
	    return prefix + "/wVendor";
	}
	
	/**
	 * 查询供应商列表
	 */
	@RequiresPermissions("foxwash:wVendor:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WVendor wVendor)
	{
		startPage();
        List<WVendor> list = wVendorService.selectWVendorList(wVendor);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出供应商列表
	 */
	@RequiresPermissions("foxwash:wVendor:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WVendor wVendor)
    {
    	List<WVendor> list = wVendorService.selectWVendorList(wVendor);
        ExcelUtil<WVendor> util = new ExcelUtil<WVendor>(WVendor.class);
        return util.exportExcel(list, "wVendor");
    }
	
	/**
	 * 新增供应商
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存供应商
	 */
	@RequiresPermissions("foxwash:wVendor:add")
	@Log(title = "供应商", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WVendor wVendor)
	{
		wVendor.setUuid(UUIDUtils.getUUID());
		wVendor.setCreator(ShiroUtils.getUserId());
		return toAjax(wVendorService.insertWVendor(wVendor));
	}

	/**
	 * 修改供应商
	 */
	@GetMapping("/edit/{vendorId}")
	public String edit(@PathVariable("vendorId") Long vendorId, ModelMap mmap)
	{
		WVendor wVendor = wVendorService.selectWVendorById(vendorId);
		mmap.put("wVendor", wVendor);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存供应商
	 */
	@RequiresPermissions("foxwash:wVendor:edit")
	@Log(title = "供应商", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WVendor wVendor)
	{
		wVendor.setModifier(ShiroUtils.getUserId());
		return toAjax(wVendorService.updateWVendor(wVendor));
	}
	
	/**
	 * 删除供应商
	 */
	@RequiresPermissions("foxwash:wVendor:remove")
	@Log(title = "供应商", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wVendorService.deleteWVendorByIds(ids));
	}

	/**
	 * 服务状态修改
	 */
	@Log(title = "供应商管理", businessType = BusinessType.UPDATE)
	@RequiresPermissions("foxwash:wVendor:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(WVendor wVendor)
	{
		return toAjax(wVendorService.changeStatus(wVendor));
	}
	
}
